<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login  extends CI_Controller {
    
    function index()
    {
        if ( $this->session->userdata('isLoggedIn') ){
            redirect('/zwop_main/show_main');
        }else{
            $this->show_login(false);
        }
    }
    function login_user() {
        $this->load->model('user_m');
        $username = $this->input->post('username');
        $passwd = $this->input->post('password');

        if ( $username && $passwd && $this->user_m->validate_user($username,$passwd) ) {
            redirect('/zwop_main/show_main');
        }else{
            $this->show_login(true);
        }
    }

    function show_login( $show_error=false ){
        $data['login_error'] = $show_error;
        $this->load->helper('form');
        $this->load->view('login',$data);
    }
    function logout_user() {
        $this->session->sess_destroy();
        $this->index();
    }
}
